<?php
/**
 * This file is part of DomBankLink.
 * 
 * DomBankLink is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DomBankLink is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DomBankLink.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @link http://inditel.ee/
 * @copyright 2007-2009 Inditel Meedia OÜ
 * @author Oliver Leisalu <oliver@inditel.ee>
 */


/**
 * @author Oliver Leisalu
 * @package DomBankLink
 * @orm tablename bank_wap_payments
 */
class DomWapPayment {
	
	/**
	 * @orm char(12)
	 */
	public $phoneNr;
	/**
	* @orm plugin DomArDateTime()
	*/
	public $datetime;
	/**
	* @orm char(15)
	*/
	public $ip;
	/**
	* @orm float(7,2)
	*/
	public $price;
	/**
	* @orm char(3)
	*/
	public $currency;
	/**
	* @orm enum({sentToBank,ok,cancel,error}) index
	*/
	public $status = 0;
	/**
	 * @orm char(6)
	 */
	public $operator;
	/**
	 * @orm char(10) index
	 */
	public $profile;
	/**
	* @orm char(255)
	*/
	public $description;
	
	const OK = 'ok';
	const CANCEL = 'cancel';
	const ERROR = 'error';
	const SENT_TO_BANK = 'sentToBank';
	
	/**
	 * Creates new payment object
	 *
	 * @param Float $price
	 * @param String $description
	 * @param String $profile
	 * @return BankPayment
	 */
	public static function createNew( $phoneNr, $price, $description, $profile ) {
		$class = get_called_class();
		$payment = new $class();
		$payment->price = (float)$price;
		$payment->description = (string)$description;
		$payment->profile = (string)strtolower($profile);
		
		$link = DomBankLink::getLink( $profile );
		if( !$link ) throw new  RuntimeException('BankLink profile "'.$profile.'" doesn\'t exist!');
		$payment->operator = $link->getKey();
		$payment->currency = strtolower( $link->getCurrency() );
		
		$payment->datetime = 'now';
		$payment->ip = ip();
		
		return $payment;
	}
	
	
	public function pay() {
		
	}
	
	
	
}
?>